//
//  ZYMemoryCache.m
//  ZYWebImage
//
//  Created by wangzhipan on 2025/3/14.
//

#import "ZYMemoryCache.h"
#import <UIKit/UIKit.h>

@implementation ZYMemoryCache
- (instancetype)initWithMaxCost:(NSUInteger)cost
                  maxCountLimit:(NSUInteger)count
{
    if (self = [super init]) {
        self.totalCostLimit = cost;
        self.countLimit = count;
        
        [self p_addNotification];
    }
    return self;
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)p_addNotification
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveMemoryWarning) name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
}

- (void)receiveMemoryWarning
{
    [self removeAllObjects];
}
@end
